const moment = require('moment')
const md5 = require('md5')
class Person{
      constructor(){}
            // 编辑
          edit(req,res){
            let {username,phone,email,tag,img}=req.body
            let sql='update `users` set `username`="'+username+'",`phone`="'+phone+'",`img`="'+img+'",`mtime`="'+ moment().format('YYYY-MM-DD HH:m:s')+'", `email`="'+email+'",`tag`=\''+tag+'\' where `id`="'+req.session.loginInfo.id+'"'
            req.db.query(sql).then(()=>{
              res.send({
                error:0,
                message:'success'
              })
            }).catch(error=>{
              console.log(error)
              res.send({
                error:30,
                message:'update fail'
              })
            })
          }

      //     修改密码
      pass(req,res){
            let {password}=req.body
            let sql='update `users` set `password`="'+md5(password)+'",`mtime`="'+ moment().format('YYYY-MM-DD HH:m:s')+'" where `id`="'+req.session.loginInfo.id+'"'
            req.db.query(sql).then(()=>{
                  res.send({
                    error:0,
                    message:'success'
                  })
                }).catch(error=>{
                  console.log(error)
                  res.send({
                    error:30,
                    message:'update fail'
                  })
            })
      }
}

module.exports=new Person()